package com.sharemarking.wa.platform.service;

import com.sharemarking.wa.common.ResponseParams;
import com.sharemarking.wa.common.entity.Feedback;
import com.sharemarking.wa.common.exception.RequestException;
import com.sharemarking.wa.platform.mapper.FeedbackMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author dxy
 */
@Service
public class FeedbackService {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private SecurityService ss;
    @Autowired
    private FeedbackMapper feedbackMapper;

    public ResponseParams<?> addFeedback() throws Exception{
        Integer memberId = ss.getCurrentUserId();

        String feedbackStr = request.getParameter("feedback");

        if (StringUtils.isEmpty(feedbackStr)) {
            throw RequestException.create(ResponseParams.requiredParamsIsMissing("feedback"));
        }

        Feedback feedback = new Feedback();
        feedback.setFeedback(feedbackStr);
        feedback.setMemberId(memberId);
        feedback.setCreateDate(new Date());

        feedbackMapper.insert(feedback);

        return ResponseParams.ok(null);
    }




}
